package com.yimi.yinhepda.db.table;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import com.uce.pda.bean.WebsiteScanData;
import com.yimi.yinhepda.utils.Common;

/**
 * @author: lj
 * Date: 2019/10/8 17:35
 * Description:功能按钮表
 */
@DatabaseTable(tableName = "FuncBtnTable")
public class FuncBtnTable implements Comparable<FuncBtnTable> {
    @DatabaseField(generatedId = true)
    private transient Long id;
    @DatabaseField()
    private int picId;
    /**
     * 功能名称
     */
    @DatabaseField()
    private String name;
    /**
     * 功能名称code
     */
    @DatabaseField(index = true)
    private String nameCode;
    /**
     * 0-不常用，1-常用
     */
    @DatabaseField()
    private int isCommUse;
    /**
     * 0-可用，1-不可用
     */
    @DatabaseField()
    private int isEnable;
    /**
     * 常用排序ID
     */
    @DatabaseField()
    private int sortId;
    /**
     * 组ID
     */
    @DatabaseField()
    private int groupId;
    /**
     * 组code
     */
    @DatabaseField()
    private String groupCode;
    /**
     * 组名
     */
    @DatabaseField()
    private String groupName;
    /**
     * 是否已添加：0-未添加，1-已添加
     */
    @DatabaseField()
    private int isAdd;
    /**
     * 部门类型：0-网点，1-分拨,2-通用
     */
    @DatabaseField()
    private int deptType;
    /**
     * 功能类型：0-快运，1-快递
     */
    @DatabaseField()
    private int funcType;

    public FuncBtnTable() {
    }

    public FuncBtnTable(String name, String nameCode, int isCommUse, String groupCode, int isAdd, int deptType, int funcType) {
        this.name = name;
        this.nameCode = nameCode;
        this.isCommUse = isCommUse;
        this.groupCode = groupCode;
        this.isAdd = isAdd;
        this.deptType = deptType;
        this.funcType = funcType;
        setGroupItem(groupCode);
    }

    public FuncBtnTable(String name, String nameCode, int isCommUse, int sortId, String groupCode, int isAdd, int deptType, int funcType) {
        this.name = name;
        this.nameCode = nameCode;
        this.isCommUse = isCommUse;
        this.sortId = sortId;
        this.groupCode = groupCode;
        this.isAdd = isAdd;
        this.deptType = deptType;
        this.funcType = funcType;
        setGroupItem(groupCode);
    }

    /**
     * 分组设置
     */
    private void setGroupItem(String groupCode) {
        if (groupCode.equals(Common.FUNC_GROUP_OPTER_CODE)) {
            this.groupId = 0;
            this.groupName = Common.FUNC_GROUP_OPTER;
        } else if (groupCode.equals(Common.FUNC_GROUP_INSIDE_CODE)) {
            this.groupId = 1;
            this.groupName = Common.FUNC_GROUP_INSIDE;
        } else {
            this.groupId = 2;
            this.groupName = Common.FUNC_GROUP_EXCEPTION;
        }
    }

    public FuncBtnTable(String name, String nameCode, int isCommUse, int sortId, int picId) {
        this.name = name;
        this.nameCode = nameCode;
        this.isCommUse = isCommUse;
        this.sortId = sortId;
        this.picId = picId;
    }

    public int getDeptType() {
        return deptType;
    }

    public void setDeptType(int deptType) {
        this.deptType = deptType;
    }

    public int getFuncType() {
        return funcType;
    }

    public void setFuncType(int funcType) {
        this.funcType = funcType;
    }

    public int getIsAdd() {
        return isAdd;
    }

    public void setIsAdd(int isAdd) {
        this.isAdd = isAdd;
    }

    public String getGroupCode() {
        return groupCode;
    }

    public void setGroupCode(String groupCode) {
        this.groupCode = groupCode;
    }

    public int getGroupId() {
        return groupId;
    }

    public void setGroupId(int groupId) {
        this.groupId = groupId;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public int getPicId() {
        return picId;
    }

    public void setPicId(int picId) {
        this.picId = picId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNameCode() {
        return nameCode;
    }

    public void setNameCode(String nameCode) {
        this.nameCode = nameCode;
    }

    public int getIsCommUse() {
        return isCommUse;
    }

    public void setIsCommUse(int isCommUse) {
        this.isCommUse = isCommUse;
    }

    public int getIsEnable() {
        return isEnable;
    }

    public void setIsEnable(int isEnable) {
        this.isEnable = isEnable;
    }

    public int getSortId() {
        return sortId;
    }

    public void setSortId(int sortId) {
        this.sortId = sortId;
    }

    @Override
    public int compareTo(@NonNull FuncBtnTable o) {
        return this.sortId - o.getSortId();
    }

    public static FuncBtnTable updateDataTable(FuncBtnTable oldTable, FuncBtnTable newTable) {
        oldTable.setPicId(newTable.getPicId());
        oldTable.setName(newTable.getName());
        oldTable.setNameCode(newTable.getNameCode());
        oldTable.setIsCommUse(newTable.getIsCommUse());
        oldTable.setIsEnable(newTable.getIsEnable());
        oldTable.setSortId(newTable.getSortId());
        oldTable.setGroupId(newTable.getGroupId());
        oldTable.setGroupCode(newTable.getGroupCode());
        oldTable.setGroupName(newTable.getGroupName());
        oldTable.setIsAdd(newTable.getIsAdd());
        oldTable.setDeptType(newTable.getDeptType());
        oldTable.setFuncType(newTable.getFuncType());
        return oldTable;
    }


    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj instanceof FuncBtnTable) {
            FuncBtnTable u = (FuncBtnTable) obj;
            if (!TextUtils.isEmpty(this.nameCode)) {
                return this.nameCode.equals(u.nameCode);
            }
        } else if (obj instanceof String) {
            String u = (String) obj;
            return this.nameCode.equals(u);
        }
        return super.equals(obj);
    }
}
